package masterjava.common.client.gxt.base.info;

import com.extjs.gxt.ui.client.Style;
import com.extjs.gxt.ui.client.core.XTemplate;
import com.extjs.gxt.ui.client.data.BaseModelData;
import com.extjs.gxt.ui.client.data.ModelData;
import com.extjs.gxt.ui.client.util.Util;
import com.extjs.gxt.ui.client.widget.Dialog;
import masterjava.common.client.gwt.settings.AppSettings;

/**
 * User: gkislin
 * Date: 8/4/11
 */
public class InfoDialog extends Dialog {
    private final XTemplate template;

    public static InfoDialog getInfoDialog(String title, Enum contentKey) {
        InfoDialog dialog = new InfoDialog(title, AppSettings.<String>get(contentKey));
        dialog.applyTemplate(new BaseModelData(AppSettings.getSettings()));
        return dialog;
    }

    public InfoDialog(String title, String template) {
        setHeading(title);
        this.template = XTemplate.create(template);
        setBodyStyleName("info-text");
        setButtons(Dialog.YES);
        setScrollMode(Style.Scroll.AUTO);
        setHideOnButtonClick(true);
        setButtonAlign(Style.HorizontalAlignment.CENTER);
    }

    public void applyTemplate(ModelData data) {
        removeAll();
        addText(template.applyTemplate(Util.getJsObject(data)));
        getItem(0).getFocusSupport().setIgnore(true);
    }
}
